package com.huajx.tuopuda.client.udp;

import com.huajx.core.util.BitUtil;
import com.huajx.util.HexUtil;
import com.huajx.util.date.DateUtil;

import java.util.Arrays;
import java.util.Date;

/**
 * @program: di-parent
 * @description:
 * @author: lisa 叶新华
 * @create: 2019-09-24 13:44
 */
public class TuopudaMessage {
    private int address;    // 板地址
    private int direct;  // 指令，功能位
    private int carId;   // 卡号
    private Date date;      // 考勤时间
    private int mark;       // 进出标志
    private byte[] bytes;   // 包体
    private int records;    // 记录数
    
    private String info;

    public int getRecords() {
        return records;
    }

    public void setRecords(int records) {
        this.records = records;
    }

    public int getAddress() {
        return address;
    }

    public void setAddress(int address) {
        this.address = address;
    }

    public int getDirect() {
        return direct;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public int getCarId() {
        return carId;
    }

    public void setCarId(int carId) {
        this.carId = carId;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public int getMark() {
        return mark;
    }

    public void setMark(int mark) {
        this.mark = mark;
    }

    public byte[] getBytes() {
        return bytes;
    }

    public void setBytes(byte[] bytes) {
        this.bytes = bytes;
    }
    public String getInfo() {
		return info;
	}
	public void setInfo(String info) {
		this.info = info;
	}

	@Override
    public String toString() {
        return "TuopudaMessage{" +
                "address=" + address +
                ", direct=" + direct +
                ", carId=" + carId +
                ", date=" + date +
                ", mark=" + mark +
                ", records=" + records +
                ", bytes=" + HexUtil.bytesToHex(bytes) +
                '}';
    }

    public String toKey() {
        return "address=" + address +
                ", carId=" + carId +
                ", direct=" + direct +
                ", date=" + DateUtil.format(date, "yyMMddHHmm");
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof TuopudaMessage) {
            TuopudaMessage message = (TuopudaMessage) obj;

            return message.toKey().equals(toKey());
        }
        return false;
    }
}
